<?php namespace Home\Controller; 
use Hdphp\Controller\Controller;
//前台默认控制器
class IndexController extends Controller{
	//构造函数(1.自定义的,2.不会覆盖父类的构造方法__construct)
	public function __init(){
		
	}
    //默认显示首页
   	public function index(){
   		
		
		//首页文章
		$arcModel = new \Common\Model\Arc;
		$data = $arcModel
				->field('aid,title,author,sendtime,cname,cid,thumb,digest')
				->join('category','category_cid','=','cid')
				->orderBy('sendtime','DESC')
				->get();
		//中间表模型
		$arcTagModel = new \Common\Model\ArcTag;
		foreach ($data as $k => $v) {
			//article_tag中间表和tag表关联
			$data[$k]['tag'] = $arcTagModel->where("article_aid={$v['aid']}")->join('tag','tag_tid','=','tid')->get();
		}
		//自己打印一下做测试
		//p($data);
		View::with('data',$data);
		
		
   	    View::make();
   	}
}
